package com.xxx.video.commen.utils;


import android.content.Intent;

import com.xxx.video.VideoApplication;
import com.xxx.video.commen.beans.BaseBean;
import com.xxx.video.commen.configs.UserManager;
import com.xxx.video.login.activitys.LoginActivity;

public class ResponseUtils {
    private static ResponseUtils mResponseUtils = null;

    private ResponseUtils() {
    }

    public static ResponseUtils getInstance() {
        if (mResponseUtils == null) {
            synchronized (ResponseUtils.class) {
                if (mResponseUtils == null) {
                    mResponseUtils = new ResponseUtils();
                }
            }
        }
        return mResponseUtils;
    }

    /**
     * is no error
     *
     * @param baseBean bean
     */
    public boolean isNoError(BaseBean baseBean) {
        if (baseBean == null) {
            return false;
        }
        if (baseBean.code == 0) {
            return true;
        } else if (baseBean.code == 401) {
            /*
             * token失效
             */
            UserManager.getInstance().logOut();
            if (VideoApplication.getTopActivity() != null) {
                Intent intent = new Intent(VideoApplication.getTopActivity(), LoginActivity.class);
                VideoApplication.getTopActivity().startActivity(intent);
            }
            return false;
        } else {
            ToastUtils.showError(baseBean.msg);
            return false;
        }
    }
}
